<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>验收详情</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../../../css/mui.min.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <style type="text/css">
      .mui-navigate-right:after,
      .mui-push-right:after {
        right: 0;
      }

      .square-item {
        width: 30px;
        height: 30px;
        border-radius: 3px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-top: 10px;
        margin-right: 10px;
        background: #f5f6f7;
        color: #333;
      }
      .square-item.bg-blue {
        color: #ffffff;
        background: #3188fe;
      }
      .square-item img {
        width: 15px;
        height: 15px;
      }

      .mui-radio.mui-left input[type='radio'] {
        left: 0;
      }

      .mui-radio.mui-left label {
        padding-left: 38px;
      }

      .areas {
        background-color: #f1f3f7;
      }

      .tips {
        text-align: center;
        font-weight: bold;
        line-height: 40px;
        font-size: 18px;
        border-bottom: 1px solid #dcdcdc;
      }
      .tips-list {
        margin-top: 40%;
      }

      .mui-navigate-right:after {
        right: 0;
      }

      .option {
        display: flex;
        justify-content: space-around;
        margin-top: 20px;
      }

      .option button {
        width: 80px;
      }
	  .tips-lx{position: absolute;right: 0;top: 0;background: #dfdfdf; padding: 5px;border-radius: 5px;}
	  .sub-accept{ padding-bottom: 20px;}
	  .sub-accept button{ width: 100%; height: 40px; border-radius: 20px;}
    </style>
  </head>

  <body>
    <header class="mui-bar mui-bar-nav">
      <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left text-white"></a>
      <h1 class="mui-title">详情</h1>
    </header>
    <div class="mui-content page-wrap" id="container" v-cloak>
      <div class="page-scroll">
        <div class="mui-card padding-lr" style="position: relative;">
			<span class="tips-lx" v-if="islx">当前是离线数据</span>
          <div class="padding-tb text-center border-bottom color-blue" v-if="wt && wt.startTime">
            <div>工作票时间</div>
            <div class="margin-top-xs">{{wt.startTime}} - {{wt.endTime}}</div>
          </div>
          <div class="padding-tb text-center border-bottom" v-else>
            <img src="../img/gongzuopiao_weikai.png" width="60" />
            <div class="color-999 margin-top-xs">工作票未开</div>
          </div>

          <div class="padding-tb border-bottom flex justify-between">
            <div>工器具清单</div>
            <div class="link" data-url="./materialList.html" style="width: 50px">
              <span class="color-blue">查看</span>
              <span class="padding-right mui-navigate-right"></span>
            </div>
          </div>
          <div class="padding-tb border-bottom" v-if="ts.length">
            <!--v-if="ts.length> 0"-->
            <div class="flex justify-between margin-bottom-sm" style="position: relative">
              <div>该设备是关键敏感设备，有以下风险描述</div>
              <div class="link" data-url="./riskList.html" style="width: 50px">
                <span class="color-blue">进入</span>
                <span class="padding-right mui-navigate-right"></span>
              </div>
            </div>
            <div v-for="(a,index) in ts" :key="index">
              <span v-if="a.taskWps.length > 0">{{a.deviceName}}</span>
              <div class="flex flex-wrap">
                <div :class="['square-item', item.status==4 ? 'bg-blue': '']" v-for="(item, i) in a.taskWps" :key="item.id" @click="toImplement(item, i)">
                  <img src="../img/gongzuopiao_duigou.png" v-if="item.status==4" />
                  <span v-else>{{i + 1}}</span>
                </div>
              </div>

              <div v-for="(b,index) in a.childs" :key="index">
                <span v-if="b.taskWps.length > 0">{{b.parentName}}/{{b.deviceName}}</span>
                <div class="flex flex-wrap">
                  <div :class="['square-item', item.status==4 ? 'bg-blue': '']" v-for="(item, i) in b.taskWps" :key="item.id" @click="toImplement(item, i)">
                    <img src="../img/gongzuopiao_duigou.png" v-if="item.status==4" />
                    <span v-else>{{i + 1}}</span>
                  </div>
                </div>
                <div v-for="(c,index) in b.childs" :key="index">
                  <span v-if="c.taskWps.length > 0">{{c.parentName}}/{{c.deviceName}}</span>
                  <div class="flex flex-wrap">
                    <div :class="['square-item', item.status==4 ? 'bg-blue': '']" v-for="(item, i) in c.taskWps" :key="item.id" @click="toImplement(item, i)">
                      <img src="../img/gongzuopiao_duigou.png" v-if="item.status==4" />
                      <span v-else>{{i + 1}}</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <div class="padding-tb border-bottom">
            <div class="flex justify-between margin-bottom-sm" style="position: relative;">
              <div>工序完成情况（共{{countWp}}个工序）</div>
              <div class="link" data-url="./workingList.html" style="width: 50px">
                <span class="color-blue">进入</span>
                <span class="padding-right mui-navigate-right"></span>
              </div>
            </div>
            <div v-for="(a,index) in wp" :key="index">
              <span v-if="a.taskWps.length > 0">{{a.deviceName}}</span>
              <div class="flex flex-wrap">
                <div :class="['square-item', item.status==4 ? 'bg-blue': '']" v-for="(item, i) in a.taskWps" :key="item.id" @click="toWorkCode(item, i)">
                  <img src="../img/gongzuopiao_duigou.png" v-if="item.status==4" />
                  <span v-else>{{showTid(item.tagId, i)}}</span>
                </div>
              </div>

              <div v-for="(b,index) in a.childs" :key="index">
                <span v-if="b.taskWps.length > 0">{{b.parentName}}/{{b.deviceName}}</span>
                <div class="flex flex-wrap">
                  <div :class="['square-item', item.status==4 ? 'bg-blue': '']" v-for="(item, i) in b.taskWps" :key="item.id" @click="toWorkCode(item, i)">
                    <img src="../img/gongzuopiao_duigou.png" v-if="item.status==4" />
                    <span v-else>{{showTid(item.tagId, i)}}</span>
                  </div>
                </div>
                <div v-for="(c,index) in b.childs" :key="index">
                  <span v-if="c.taskWps.length > 0">{{c.parentName}}/{{c.deviceName}}</span>
                  <div class="flex flex-wrap">
                    <div :class="['square-item', item.status==4 ? 'bg-blue': '']" v-for="(item, i) in c.taskWps" :key="item.id" @click="toWorkCode(item, i)">
                      <img src="../img/gongzuopiao_duigou.png" v-if="item.status==4" />
                      <span v-else>{{showTid(item.tagId, i)}}</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <div v-if="claimed == 1">
            <div class="padding-tb border-bottom">
              <div class="flex justify-between" style="position: relative">
                <div>验收结论</div>
              </div>
              <div class="flex margin-top-sm">
                <div class="mui-input-row mui-radio mui-left">
                  <label>通过</label>
                  <input v-model="resRadio" value="1" name="radio1" type="radio" />
                </div>
                <div class="mui-input-row mui-radio mui-left">
                  <label>不通过</label>
                  <input v-model="resRadio" value="2" name="radio1" type="radio" />
                </div>
              </div>
            </div>
  
            <div class="padding-tb border-bottom">
              <div class="flex justify-between" style="position: relative">
                <div>验收意见</div>
              </div>
              <div class="flex margin-top-sm">
                <textarea name="" v-model="content" class="areas" cols="30" rows="6" id="textarea" maxlength="200"></textarea>
              </div>
            </div>
			<div class="sub-accept">
				<button type="button" v-if="claimed == 1" class="mui-btn mui-btn-primary" @click="submit(false)">提交</button>
			</div>
          </div>
          
        </div>
      </div>
      

      <div class="mui-backdrop" v-show="isShowMes">
        <div class="tips-list">
          <div class="mui-card card_content padding">
            <div class="tips">工作提醒</div>
            <div class="flex justify-between padding border-bottom" @tap="tipsDetail('reminders');read1=true">
              <span>工作提醒</span>
              <span v-if="read1" class="color-blue mui-navigate-right">已阅读</span>
              <span v-else class="color-999 mui-navigate-right">未阅读</span>
            </div>
            <div class="flex justify-between padding border-bottom" @tap="tipsDetail('instruction');read2=true">
              <span>操作须知</span>
              <span v-if="read2" class="color-blue mui-navigate-right">已阅读</span>
              <span v-else class="color-999 mui-navigate-right">未阅读</span>
            </div>
            <div class="option">
              <button type="button" class="mui-btn" @click="isShowMes=false">关闭</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <script src="../../../js/mui.min.js"></script>
    <script src="../../../js/jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/mkeyplus.base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../../js/vue.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/sqlite.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/indexDBs.js"></script>
    <script type="text/javascript">
      mui.init()
      let lineType=null;
      let db={};
      const dbName = 'myDBcheck';
      const storeName = 'verifyList';
      $(document).ready(function () {
        let height = document.documentElement.clientHeight
        //防止软键盘弹出底部按钮顶上来
        $('.mui-content').css('height', height + 'px')
      })

      $('body').on('click', '.link', function () {
        if (!vm.wt || !vm.wt.id) {
          mui.toast('工作票未开')
          return
        }
        let href = $(this).data('url')
        mui.baseApp.openWindow(href, {
          projectTaskId: vm.id,
          claimed: vm.claimed
        })
      })

      let self // 当前页面
      if (window.plus) {
        plusready()
      } else {
        document.addEventListener('plusready', plusready, false)
      }

     async function plusready() {
        self = plus.webview.currentWebview()
        vm.id = self.projectTaskId
        lineType = getSysInfo();
        vm.lineType = getSysInfo();
		
        // 打开数据库 const dbName = 'myDBcheck', storeName = 'verifyList'
        await openDB(dbName, storeName, 1).then(res=>{
          console.log('openDB',res) 
          db = res;
        })
        //是否离线
        if(!lineType){
			getLineData()
			vm.islx = true
        }else{
			// await vm.submit(true)
			// 有网有离线数据
			getDataByKey(db, storeName,vm.id).then(res=>{
				console.log('是否有离线数据',res)
				if(res == undefined){
					vm.getData()
					vm.isOnlineAndOfflineData = false
				} else {
					getLineData()
					vm.isOnlineAndOfflineData = true
					vm.islx = true
				}
			})
        }
        
      }

      let vm = new Vue({
        el: '#container',
        data: {
		  isOnlineAndOfflineData: false,
		  islx: false,
          id: 3,
          isShowMes: true,
          read1: false,
          read2: false,
          resRadio: 1,
          content: '',
          cr: 100, //验收率
          wp: [], //工序集合
          ts: [], // 风险集合，
          ta: null, // 验收信息
          wt: null, //工作票
          ss: 0, //任务状态
          claimed: 0, // 任务领取状态 0 未被领取 1 自己领取 2 他人领取
          countWp: 0,
          countTs: 0,
          lineType:null,
          sensitiveList:[],
          subSensitiveList:[],
          wpList:[],
          subWpList:[],
        },
        created() {
        
        },
        methods: {
          getData() {
            plus.nativeUI.showWaiting('加载中')
            mui.baseApp.httpRequst(
              'get',
              '/app/api/check/task/detail/' + this.id,
              {},
              (res) => {
                plus.nativeUI.closeWaiting()
                console.log('在线数据',res)
                this.cr = res.taskAcceptanceRate //验收率
                this.wp = res.wpItemList
                this.ts = res.sensitiveList
                this.ta = res.acceptance
                this.wt = res.workTicket
                this.ss = res.status
                this.claimed = res.claimed
                // 统计工序个数
                let arr = []
                Object.values(res.wpItemList).forEach((a, i) => {
                  arr.push(a.taskWps.length)
                  a.childs.forEach((b, index) => {
                    arr.push(b.taskWps.length)
                    b.childs.forEach((c, index) => {
                      arr.push(c.taskWps.length)
                    })
                  })
                })
                vm.countWp = arr.length ? arr.reduce((x, y) => x + y): 0
                
                // 统计敏感个数
                let tsarr = []
                Object.values(res.sensitiveList).forEach((a, i) => {
                  tsarr.push(a.taskWps.length)
                  a.childs.forEach((b, index) => {
                    tsarr.push(b.taskWps.length)
                    b.childs.forEach((c, index) => {
                      tsarr.push(c.taskWps.length)
                    })
                  })
                })
                vm.countTs = tsarr.length? tsarr.reduce((x, y) => x + y) : 0
              },
              (err) => {
                plus.nativeUI.closeWaiting()
              }
            )
          },
          showTid(tid, i) {
            if (tid == 271) {
              return '停'
            } else if (tid == 272) {
              return '现'
            } else if (tid == 273) {
              return '旁'
            } else {
              return i + 1
            }
          },
          toImplement(row, i) {
            if (!this.wt || !this.wt.id) {
              mui.toast('工作票未开')
              return
            }
            
            let arr = []
            let currentIndex = 0 // 当前点击工序索引
            vm.ts.forEach((a, i) => {
              arr = arr.concat(a.taskWps)
              a.childs.forEach((b, index) => {
                arr = arr.concat(b.taskWps)
                b.childs.forEach((c, index) => {
                  arr = arr.concat(c.taskWps)
                })
              })
            })
            let list = arr.map((wp, index) => {
              wp.index = index
              if (wp.id == row.id) {
                currentIndex = wp.index
              }
              return {
                index,
                status: wp.status,
                id: wp.id
              }
            })
            mui.baseApp.openWindow('./implement.html', {
              projectTaskSensitiveId: row.id,
              i: currentIndex,
              list,
              claimed: this.claimed,
              dbId:this.id
            })
          },
          toWorkCode(row, i) {
            if (!this.wt || !this.wt.id) {
              mui.toast('工作票未开')
              return
            }
            
            let arr = []
            let currentIndex = 0 // 当前点击工序索引
            vm.wp.forEach((a, i) => {
              arr = arr.concat(a.taskWps)
              a.childs.forEach((b, index) => {
                arr = arr.concat(b.taskWps)
                b.childs.forEach((c, index) => {
                  arr = arr.concat(c.taskWps)
                })
              })
            })
            let list = arr.map((wp, index) => {
              wp.index = index
              if (wp.id == row.id) {
                currentIndex = wp.index
              }
              return { 
                index,
                status: wp.status,
                id: wp.id
              }
            })
            
            mui.baseApp.openWindow('./workingCode.html', {
              wpid: row.id,
              i: currentIndex,
              list,
              claimed: this.claimed,
              dbId:this.id
            })
          },
          tipsDetail(type) {
            mui.baseApp.openWindow('../performTasks/carryoutTipsDetail.html?type=' + type)
          },
          submit(isauto) {
            let then= this
            if(!lineType){
              // mui.toast('请检查网络是否连接！')
              mui.confirm('请检查网络！是否需要保存离线编辑内容？','提示',['是','否'],function(item){
                console.log('对话框提示',item)
                if(item.index==0){
                  getLineData()
                }else{
                  getDel(vm.id)
                }
              })
              return
            }else {
             getDataByKey(db, storeName,vm.id).then(res=>{
               let count = 0
               res&&res.wpItemList&&res.wpItemList.forEach((a, i) => {
                 a.taskWps.forEach(item => {
                   if (item.status==4) {
                     count++
                   }
                    
                 })
                 a.childs.forEach((b, index) => {
                   b.taskWps.forEach(item => {
                     if (item.status==4) {
                       count++
                     }
                      
                   })
                   b.childs.forEach((c, index) => {
                     c.taskWps.forEach(item => {
                       if (item.status==4) {
                         count++
                       }
                     })
                   })
                 })
               })
               res&&res.sensitiveList&&res.sensitiveList.forEach((a, i) => {
                 a.taskWps.forEach(item => {
                   if (item.status==4) {
                     count++
                   }
                 })
                 a.childs.forEach((b, index) => {
                   b.taskWps.forEach(item => {
                     if (item.status==4) {
                       count++
                     }
                      
                   })
                   b.childs.forEach((c, index) => {
                     c.taskWps.forEach(item => {
                       if (item.status==4) {
                         count++
                       }
                     })
                   })
                 })
               })
                 if(res && res.id==vm.id&&count>0){
                   mui.confirm('当前有离线数据，是否需要保存？','提示',['是','否'],async function(item){
                     console.log('对话框提示',item)
                     if(item.index==0){
                        console.log('122','res')
                        await getLineData()
                        await then.allSubs(true)
                       // this.lineSubmit()
                     }else{
					   // 取消提交
                       // getDel(vm.id)
                       // if(!isauto){
                       //   then.allSubs(false)
                       // }
                       // getDel(taskId)
                     }
                   })
                 }else{
                   if(!isauto){
                     then.allSubs(false)
                   }
                 }
               })
            }
             
          },
          
          allSubs(isTrue){
            let count = 0
            let total = this.countWp + this.countTs
            let wpList = []
            let subWpList = []
            vm.wp&&vm.wp.forEach((a, i) => {
              a.taskWps.forEach(item => {
                if (item.status==4) {
                  count++
                }
                if(item.details){
                  if(item.status==4){
                    // delete task.details.subWps
                    this.wpList.push(item.details)
                  }
                  if(item.details.subWps&&item.details.subWps.length>0){
                    // this.subWpList.concat(task.details.subWps)
                    item.details.subWps.forEach(items=>{
                      if(item.status==4){
                      this.subWpList.push(items)
                      }
                    })
                  }
                }
              })
              a.childs.forEach((b, index) => {
                b.taskWps.forEach(item => {
                  if (item.status==4) {
                    count++
                  }
                  if(item.details){
                    if(item.status==4){
                      // delete task.details.subWps
                      this.wpList.push(item.details)
                    }
                    if(item.details.subWps&&item.details.subWps.length>0){
                      // this.subWpList.concat(task.details.subWps)
                      item.details.subWps.forEach(items=>{
                        if(item.status==4){
                        this.subWpList.push(items)
                        }
                      })
                    }
                  }
                })
                b.childs.forEach((c, index) => {
                  c.taskWps.forEach(item => {
                    if (item.status==4) {
                      count++
                    }
                    if(item.details){
                      if(item.status==4){
                        // delete task.details.subWps
                        this.wpList.push(item.details)
                      }
                      if(item.details.subWps&&item.details.subWps.length>0){
                        // this.subWpList.concat(task.details.subWps)
                        item.details.subWps.forEach(items=>{
                          if(item.status==4){
                          this.subWpList.push(items)
                          }
                        })
                      }
                    }
                  })
                })
              })
            })
            this.sensitiveList=[]
            this.subSensitiveList=[]
            vm.ts&&vm.ts.forEach((a, i) => {
              a.taskWps.forEach(item => {
                if (item.status==4) {
                  count++
                }
                if(item.details){
                  if(item.status==4){
                    // delete task.details.subWps
                    this.sensitiveList.push(item.details)
                  }
                  if(item.details.subWps&&item.details.subWps.length>0){
                    // this.subWpList.concat(task.details.subWps)
                    item.details.subWps.forEach(items=>{
                      if(item.status==4){
                      this.subSensitiveList.push(items)
                      }
                    })
                  }
                }
              })
              a.childs.forEach((b, index) => {
                b.taskWps.forEach(item => {
                  if (item.status==4) {
                    count++
                  }
                  if(b.details){
                    if(item.status==4){
                      // delete task.details.subWps
                      this.sensitiveList.push(item.details)
                    }
                    if(item.details.subWps&&item.details.subWps.length>0){
                      // this.subWpList.concat(task.details.subWps)
                      item.details.subWps.forEach(items=>{
                        if(item.status==4){
                        this.subSensitiveList.push(items)
                        }
                      })
                    }
                  }
                })
                b.childs.forEach((c, index) => {
                  c.taskWps.forEach(item => {
                    if (item.status==4) {
                      count++
                    }
                    if(item.details){
                      if(item.status==4){
                        // delete task.details.subWps
                        this.sensitiveList.push(item.details)
                      }
                      if(item.details.subWps&&item.details.subWps.length>0){
                        // this.subWpList.concat(task.details.subWps)
                        item.details.subWps.forEach(item=>{
                          if(item.status==4){
                          this.subSensitiveList.push(item)
                          }
                        })
                      }
                    }
                  })
                })
              })
            })
            console.log('验收率11111111111111111',count,total,this.cr)
            if ((count / total) * 100 < this.cr) {
              mui.toast('验收率没达标')
              return
            }
            if (!this.wt || !this.wt.id) {
              mui.toast('工作票未开')
              return
            }
            if (this.resRadio == 2 && !this.content) {
              mui.toast('请填写验收意见')
              return
            }
            // return false
            if(isTrue){
              this.lineSubmit()
              return
            }
            let params = {
              tid: this.id,
              c: this.resRadio,
              o: this.content
            }
            if (this.ta && this.ta.id) {
              params.id = this.ta.id
            }
            let loading = plus.nativeUI.showWaiting('提交中')
            
            mui.baseApp.httpRequst(
              'post',
              '/app/api/check/acceptance',
              params,
              (res) => {
                console.log(res)
                loading.close()
                mui.toast('提交成功')
                mui.fire(self.opener(), 'back', {})
                mui.fire(self.opener().opener(), 'back', {})
                mui.back()
              },
              (err) => {
                loading.close()
              }
            )
          },
          // anomalyInfo.files // faultInfo.files
          async upLoadtest(arr) {
            console.log('图片6666',JSON.stringify(arr))
            if(arr.length>0){
              for (let i=0;i<arr.length;i++) {
                // checkInputs 文件
                if(arr[i].checkInputs&&arr[i].checkInputs.length>0){
                  let items=arr[i].checkInputs
                  console.log('aaaaaaaaaa',JSON.stringify(items))
                   for(let j=0;j<items.length;j++){
                     let inputs=items[j]
                     console.log('ddddddddddd',JSON.stringify(inputs))
                     if(inputs&&inputs.files&&inputs.files.length>0){
                       // let psths=inputs
                       for(let v=0; v < inputs.files.length; v++){
                         if(inputs.files[v].filePath){
                           let isStr = inputs.files[v].filePath.indexOf('file:')
                           if(isStr!=-1){
                             let lists=await new Promise((resolve, reject)=>{
                                   mui.baseApp.upLoadFile(inputs.files[v].filePath,function(res) {
                                   console.log('返回数据',JSON.stringify(res))
                                   // plus.nativeUI.closeWaiting()
                                   resolve(res)
                                 }) 
                              })
                              let objs={
                                   fileId: lists.data.id,
                                   filePath: lists.data.fileDirectory
                                 }
                               console.log('lis列表aaaa',JSON.stringify(lists))
                               // console.log('lis列表aaaa',JSON.stringify(fileList))
                               this.$set(inputs.files,v,objs)
                           }
                            
                         }
                       }
                     }
                   }
                }
                // inputs 文件类型 
                if(arr[i]&&arr[i].inputs&&arr[i].inputs.length>0){
                  let items=arr[i].inputs
                  console.log('aaaaaaaaaa',JSON.stringify(items))
                   for(let j=0;j<items.length;j++){
                     let inputs=items[j]
                     console.log('ddddddddddd',JSON.stringify(inputs))
                     if(inputs&&inputs.files&&inputs.files.length>0){
                       // let psths=inputs
                       for(let v=0; v < inputs.files.length; v++){
                         if(inputs.files[v].filePath){
                           let isStr = inputs.files[v].filePath.indexOf('file:')
                           if(isStr!=-1){
                             let lists=await new Promise((resolve, reject)=>{
                                   mui.baseApp.upLoadFile(inputs.files[v].filePath,function(res) {
                                   console.log('返回数据',JSON.stringify(res))
                                   // plus.nativeUI.closeWaiting()
                                   resolve(res)
                                 }) 
                              })
                              let objs={
                                   fileId: lists.data.id,
                                   filePath: lists.data.fileDirectory
                                 }
                               console.log('lis列表aaaa',JSON.stringify(lists))
                               // console.log('lis列表aaaa',JSON.stringify(fileList))
                               this.$set(inputs.files,v,objs)
                           }
                            
                         }
                          
                       }
                     }
                   }
                }
                // 是否正常
                console.log('是否正常111111',JSON.stringify(arr[i]))
                if(arr[i]&&arr[i].anomalyInfo&&arr[i].anomalyInfo.files&&arr[i].anomalyInfo.files.length>0){
                   let items=arr[i].anomalyInfo.files
                       for(let j=0;j<items.length;j++){
                         if(items[j]&&items[j].filePath){
                           let isStr = items[j].filePath.indexOf('file:')
                           if(isStr!=-1){
                             console.log('图片66669999',JSON.stringify(items[j].filePath))
                             let lists=await new Promise((resolve, reject)=>{
                                   mui.baseApp.upLoadFile(items[j].filePath,function(res) {
                                   console.log('返回数据',JSON.stringify(res))
                                   resolve(res)
                                 }) 
                              })
                              let objs={
                                   fileId: lists.data.id,
                                   filePath: lists.data.fileDirectory
                                 }
                               console.log('lis列表aaaa',JSON.stringify(lists))
                               this.$set(items,j,objs)
                           }
                            
                         }
                       }
                       console.log('lis列表bbbbbb',JSON.stringify(items))
                   }
                   // 是否通过
                   console.log('是否通过222222',JSON.stringify(arr[i]))
                   if(arr[i]&&arr[i].passInfo&&arr[i].passInfo.files&&arr[i].passInfo.files.length>0){
                      let items=arr[i].passInfo.files
                          for(let j=0;j<items.length;j++){
                            if(items[j]&&items[j].filePath){
                              console.log('图片passInfo',JSON.stringify(items[j].filePath))
                              let isStr = items[j].filePath.indexOf('file:')
                              if(isStr!=-1){
                                let lists=await new Promise((resolve, reject)=>{
                                      mui.baseApp.upLoadFile(items[j].filePath,function(res) {
                                      console.log('返回数据',JSON.stringify(res))
                                      resolve(res)
                                    }) 
                                 })
                                 let objs={
                                      fileId: lists.data.id,
                                      filePath: lists.data.fileDirectory
                                    }
                                  console.log('lis列表aaaa',JSON.stringify(lists))
                                  this.$set(items,j,objs)
                              }
                              
                            }
                          }
                          console.log('lis列表bbbbbb',JSON.stringify(items))
                      }
                   // 生成缺陷
                   if(arr[i]&&arr[i].faultInfo&&arr[i].faultInfo.files.length>0){
                      let items=arr[i].faultInfo.files
                          for(let j=0;j<items.length;j++){
                            if(items[j]&&items[j].filePath){
                              console.log('图片66669999',JSON.stringify(items[j].filePath))
                              let isStr = items[j].filePath.indexOf('file:')
                              if(isStr!=-1){
                                let lists=await new Promise((resolve, reject)=>{
                                      mui.baseApp.upLoadFile(items[j].filePath,function(res) {
                                      console.log('返回数据',JSON.stringify(res))
                                      // plus.nativeUI.closeWaiting()
                                      resolve(res)
                                    }) 
                                 })
                                 let objs={
                                      fileId: lists.data.id,
                                      filePath: lists.data.fileDirectory
                                    }
                                  console.log('lis列表aaaa',JSON.stringify(lists))
                                  this.$set(items,j,objs)
                              }
                            }
                          }
                          console.log('lis列表bbbbbb',JSON.stringify(items))
                      }
                      // 负责人signInfo
                      if(arr[i]&&arr[i].signInfo&&arr[i].signInfo.takeImg&&arr[i].signInfo.takeImg.filePath){
                        let isStra = arr[i].signInfo.takeImg.filePath.indexOf('file:')
                        if(isStra!=-1){
                          let lists=await new Promise((resolve, reject)=>{
                                mui.baseApp.upLoadFile(arr[i].signInfo.takeImg.filePath,function(res) {
                                console.log('返回数据',JSON.stringify(res))
                                // plus.nativeUI.closeWaiting()
                                resolve(res)
                              }) 
                           })
                           let objs={
                                fileId: lists.data.id,
                                filePath: lists.data.fileDirectory
                              }
                            console.log('lis列表aaaa',JSON.stringify(lists))
                            // console.log('lis列表aaaa',JSON.stringify(fileList))
                            this.$set(arr[i].signInfo.takeImg,'filePath',objs.filePath)
                            this.$set(arr[i].signInfo.takeImg,'fileId',objs.fileId)
                        }
                         
                      }
                      // 签字signImg
                      if(arr[i]&&arr[i].signInfo&&arr[i].signInfo.signImg&&arr[i].signInfo.signImg.filePath){
                        let isStrs = arr[i].signInfo.signImg.filePath.indexOf('file:')
                        if(isStrs!=-1){
                          let lists=await new Promise((resolve, reject)=>{
                                mui.baseApp.upLoadFile(arr[i].signInfo.signImg.filePath,function(res) {
                                console.log('返回数据',JSON.stringify(res))
                                // plus.nativeUI.closeWaiting()
                                resolve(res)
                              }) 
                           })
                           let objs={
                                fileId: lists.data.id,
                                filePath: lists.data.fileDirectory
                              }
                            console.log('lis列表aaaa',JSON.stringify(lists))
                            // console.log('lis列表aaaa',JSON.stringify(fileList))
                            this.$set(arr[i].signInfo.signImg,'filePath',objs.filePath)
                            this.$set(arr[i].signInfo.signImg,'fileId',objs.fileId)
                        }
                         
                      }
                }
                 
                 
            }
             
            return arr
          },
         async lineSubmit(){
            let wpList=await this.upLoadtest(this.wpList)
            let subWpList =await this.upLoadtest(this.subWpList)
            let sensitiveList=await this.upLoadtest(this.sensitiveList)
            let subSensitiveList=await this.upLoadtest(this.subSensitiveList)
             // console.log('图片1111111',JSON.stringify(wpList))
             // return 
            let params = {
              stage: '5',
              // reasons: this.arr,
              projectTaskId: this.id,
              checkOpinion:{
                opinion:this.content,
                isPass:this.resRadio
              },
              sensitiveList:sensitiveList,
              wpList:wpList, //已执行基本工序
              subSensitiveList:subSensitiveList,
              subWpList:subWpList, //已执行辅助工序
              // wpReturnList:this.wpReturn,
            }
            console.log('离线全部提交',params)
			
            let loading = plus.nativeUI.showWaiting('提交中')
            mui.baseApp.httpRequst(
              'post',
              '/app/api/check/offline/data',
              params,
              (data) => {
                console.log(data)
                if (data.code == 0) {
                 loading.close()
                 mui.toast('提交成功')
				 getDel(vm.id)
				 setTimeout(function() {
					mui.fire(self.opener(), 'back', {})
					mui.fire(self.opener().opener(), 'back', {})
					mui.back()
				 }, 500);
                 
                }
              },
              () => {
                console.log('提交失败')
                 loading.close()
              }
            )
          }
        }
      })
	  
      // 获取离线数据
      async function getLineData(){
       await getDataByKey(db, storeName,vm.id).then(res=>{
          //console.log('离线数据123',res)
          // let data=res
          vm.cr = res.acceptance.taskAcceptanceRate
          vm.wp = res.wpItemList
          vm.ts = res.sensitiveList
          vm.ta = res.acceptance
          vm.wt = res.workTicket
          vm.ss = res.taskInfo.status
          vm.claimed = res.taskInfo.claimed  == null ? 1 : res.taskInfo.claimed
          // // 统计工序个数
          let arr = []
          Object.values(vm.wp).forEach((a, i) => {
            arr.push(a.taskWps.length)
            a.childs.forEach((b, index) => {
              arr.push(b.taskWps.length)
              b.childs.forEach((c, index) => {
                arr.push(c.taskWps.length)
              })
            })
          })
          vm.countWp = arr.length ? arr.reduce((x, y) => x + y): 0
          
          // // 统计敏感个数
          let tsarr = []
          Object.values(vm.ts).forEach((a, i) => {
            tsarr.push(a.taskWps.length)
            a.childs.forEach((b, index) => {
              tsarr.push(b.taskWps.length)
              b.childs.forEach((c, index) => {
                tsarr.push(c.taskWps.length)
              })
            })
          })
          vm.countTs = tsarr.length? tsarr.reduce((x, y) => x + y) : 0
        })
            
       }
      function getSearchData(data){
        //通过游标
        cursorGetData(db, storeName).then(res=>{
          console.log('333',res)
		  
          if(res.length>0){
           let arr= res.find(msg=>{
               console.log('3331',msg.id)
               return data.id==msg.id
            })
            if(arr){
              // getUpData(data)
            }else{
              getLineAdd(data)
            }
            console.log('333100',arr)
          }else{
            // getUpData(data)
            getLineAdd(data)
          }
         }).catch(function (error) {
          console.log(error);
         })
       }
       function getLineAdd(data){
          console.log('add',data)
		  plus.nativeUI.showWaiting('离线数据下载中...')
          addData(db, storeName, data).then(res=>{
            console.log('add数据',res)
			plus.nativeUI.closeWaiting()
            mui.toast('数据缓存成功')
          })
        }
        function getUpData(data){
          updateDB(db, storeName, data)
        }
       function getDel(id){
          deleteDB(db, storeName, id)
        }
      function getSysInfo() {
		  // return false
          types = {};
          types[plus.networkinfo.CONNECTION_UNKNOW] = "未知";
          types[plus.networkinfo.CONNECTION_NONE] = "未连接网络";
          types[plus.networkinfo.CONNECTION_ETHERNET] = "有线网络";
          types[plus.networkinfo.CONNECTION_WIFI] = "WiFi网络";
          types[plus.networkinfo.CONNECTION_CELL2G] = "2G蜂窝网络";
          types[plus.networkinfo.CONNECTION_CELL3G] = "3G蜂窝网络";
          types[plus.networkinfo.CONNECTION_CELL4G] = "4G蜂窝网络";
       
          var str = types[plus.networkinfo.getCurrentType()];
          if (str == '未知' || str == '未连接网络') {
              return false;
          } else {
              return true;
          }
       
      }
      window.addEventListener('back', function (event) {
		if(!lineType){
		  getLineData()
		}else{
		  if(vm.isOnlineAndOfflineData){
			  getLineData()
		  }else{
			  vm.getData()
			  if (vm.ss == 0) {
			    //未开始改为进行中
			    mui.baseApp.httpRequst(
			      'put',
			      '/app/api/check/startCheckStatus?taskId=' + vm.id,
			      {},
			      (res) => {
			        console.log(res)
			        vm.ss = 1
			        mui.fire(self.opener().opener(), 'back', {})
			      },
			      (err) => {}
			    )
			  }
		  }
		  
		}
        
      })
    </script>
  </body>
</html>
